package com.cloud.common.gateway.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description:
 * @author: lwg
 * @createTime: 2019年11月08日 21:06:00
 */
@Configuration
public class RoutesConfig {
    @Bean
    public RouteLocator serverRouter(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("user-server", r -> r.path("/user/**")
                        .filters(f -> f.rewritePath("/user/(?<segment>.*)", "/$\\{segment}"))
                        .uri("lb://user-server"))
                .route("auth-server", r -> r.path("/auth/**")
                        .filters(f -> f.rewritePath("/auth/(?<segment>.*)", "/$\\{segment}"))
                        .uri("lb://auth-server")).build();
    }

}
